<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>双向绑定任务一</title>
</head>
<body>


<script>
    function Observer(obj) {
        this.data = {};
        let that = this;
        for (let key in obj) {
            if(obj.hasOwnProperty(key)) {
                convert(key, that, obj);
            }
        }
    }
    let convert = function (key, that, obj) {
        let _value=obj[key];
        Object.defineProperty(that.data, key, {
            get: function () {
                return console.log("你访问了" + key + "，值为" + _value);
            },
            set: function (value) {
                _value = value;
                console.log("你设置了" + key + "新的值为" + _value);
            }
        });
    };

    let people={
        name: 'youngwind',
        age: 25
    };

    let app1 = new Observer(people);
    let app2 = new Observer({
        university: 'bupt',
        major: 'computer'
    });
</script>
</body>
</html>